/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include ".\workcfgdefval.h"

#include "MAddressIP.h"

//---------------------------------------------------------------------------

WorkCfgDefVal::WorkCfgDefVal(void)
{
	localRange.Empty();
}

WorkCfgDefVal::~WorkCfgDefVal(void)
{
}

//---------------------------------------------------------------------------

void WorkCfgDefVal::SetLocalIPandMask(DWORD ipIn, DWORD maskIn)
{
	MAddressIP ipa;

	ipa.Set(ipIn);
	localRange = ipa.GetNetworkRangeEx(maskIn);
}

//---------------------------------------------------------------------------

bool WorkCfgDefVal::SetAs(WorkCfgDefValType typeIn)
{
	if(localRange.IsEmpty()) return false;

	switch(typeIn){
		case __wcdvArpPing :
			return SetAsArpPing();

		case __wcdvFindWebServers :
			return SetAsFindWebServers();

		case __wcdvFindNetworkPrinters :
			return SetAsFindNetworkPrinters();

		case __wcdvWoL :
			return SetAsWoL();

		case __wcdvFindDHCPServers :
			return SetAsFindDHCPServers();

		case __wcdvPromiscuousNodeScan :
			return SetAsPromiscuousNodeScan();

		case __wcdv6PingBcast :
			return SetAsIPv6BroadcastPing();
	}

	return false;
}

//---------------------------------------------------------------------------

bool WorkCfgDefVal::SetAsArpPing(void)
{
	Initialize();

	xFileName    = _T("exArpPing.chs");
	xDescription = _T("Ex: ARP Ping");
	xComment     = _T("Example scan configuration");
	xAddresses   = localRange;

	return true;
}

bool WorkCfgDefVal::SetAsFindWebServers(void)
{
	WorkCfgElement wce;

	Initialize();

	xFileName               = _T("exFindWebServers.chs");
	xDescription            = _T("Ex: Find Web Servers");
	xComment                = _T("Example scan configuration");
	xAddresses              = localRange;
	xShowArpDiscoveredHosts = false;

	wce.phaseType  = __wptDiscovery;
	wce.methodType = __wmtSyn;
	wce.data       = _T("80,443");
	if(!AddJob(&wce))
		return false;

	wce.phaseType  = __wptScan;
	wce.methodType = __wmtSyn;
	wce.data       = _T("21-23,25,80,110,443");
	if(!AddJob(&wce))
		return false;

	return true;
}

bool WorkCfgDefVal::SetAsFindNetworkPrinters(void)
{
	WorkCfgElement wce;

	Initialize();

	xFileName               = _T("exFindNetworkPrinters.chs");
	xDescription            = _T("Ex: Find Network Printers");
	xComment                = _T("Example scan configuration");
	xAddresses              = localRange;
	xShowArpDiscoveredHosts = false;

	xMaxSimScan             = 10;
	xMaxSimScanDns          = 4;
	xMaxSimScanIcmp         = 5;
	xMaxWaitTime            = 2000;

	wce.phaseType  = __wptDiscovery;
	wce.methodType = __wmtSyn;
	wce.data       = _T("515,9100");
	if(!AddJob(&wce))
		return false;

	wce.phaseType  = __wptScan;
	wce.methodType = __wmtSyn;
	wce.data       = _T("20,23,80,515,613,721-731,1782,9100-9102,9280-9282,9290-9292");
	if(!AddJob(&wce))
		return false;

	wce.phaseType  = __wptScan;
	wce.methodType = __wmtUdpSend;
	wce.data       = _T("161,162,631,427,1");
	if(!AddJob(&wce))
		return false;

	return true;
}

bool WorkCfgDefVal::SetAsWoL(void)
{
	WorkCfgElement wce;

	Initialize();

	xFileName      = _T("exWoL.chs");
	xDescription   = _T("Ex: WakeOnLAN");
	xComment       = _T("Example scan configuration");
	xAddresses     = localRange;
	xArpCacheOp    = __acoUse;

	wce.phaseType  = __wptDiscovery;
	wce.methodType = __wmtWakeOnLAN;
	if(!AddJob(&wce))
		return false;

	return true;
}

bool WorkCfgDefVal::SetAsFindDHCPServers(void)
{
	WorkCfgElement wce;

	Initialize();

	xFileName      = _T("exFindDHCPServers.chs");
	xDescription   = _T("Ex: Find DHCP Servers");
	xComment       = _T("Example scan configuration");
	xAddresses     = _T("127.0.0.1");
	xMimicOS       = __mosLinux_2_4;
	xArpCacheOp    = __acoIgnore;

	wce.phaseType  = __wptDiscovery;
	wce.methodType = __wmtDhcpDiscov;
	if(!AddJob(&wce))
		return false;

	return true;
}

bool WorkCfgDefVal::SetAsPromiscuousNodeScan(void)
{
	WorkCfgElement wce;

	Initialize();

	xFileName      = _T("exPromiscuousNodeScan.chs");
	xDescription   = _T("Ex: Find Promiscuous Nodes");
	xComment       = _T("Example scan configuration");
	xAddresses     = localRange;
	xArpCacheOp    = __acoIgnore;

	xShowArpDiscoveredHosts = false;
	xScanAll = false;

	wce.phaseType  = __wptDiscovery;
	wce.methodType = __wmtPromisc;
	if(!AddJob(&wce))
		return false;

	return true;
}

bool WorkCfgDefVal::SetAsIPv6BroadcastPing(void)
{
	WorkCfgElement wce;

	Initialize();

	xFileName      = _T("exIPv6BroadcastPing.chs");
	xDescription   = _T("Ex: IPv6 Broadcast Ping");
	xComment       = _T("Example scan configuration");
	xAddresses     = _T("127.0.0.1");
	xArpCacheOp    = __acoIgnore;

	wce.phaseType  = __wptDiscovery;
	wce.methodType = __wmt6PingBcast;
	if(!AddJob(&wce))
		return false;

	return true;
}

//---------------------------------------------------------------------------
